package api

import (
	"gateway/basic/config"
	__ "gateway/basic/proto/userproto"
	"gateway/handler/request"
	"gateway/handler/response"
	"github.com/gin-gonic/gin"
)

// AddAddress
// @Summary      添加地址
// @Description  添加用户地址
// @Tags         地址模块
// @Accept       json
// @Produce      json
// @Param        user  body      request.AddAddressReq  true  "地址参数"
// @Success      200  {object}  response.Response
// @Failure      400   {object}  response.Response
// @Failure      500  {object}  response.Response
// @Router       /address/add [post]
func AddAddress(c *gin.Context) {
	var req request.AddAddressReq
	if err := c.ShouldBind(&req); err != nil {
		response.ParameterError(c, "参数错误", err.Error())
		return
	}
	res, err := config.UserClient.AddAddress(c, &__.AddAddressReq{
		UserId:  req.UserId,
		Address: req.Address,
	})
	if err != nil {
		response.SrvError(c, "添加地址失败", err.Error())
		return
	}
	response.Success(c, "添加地址成功", res)
}
// UpdateAddress
// @Summary      更新地址
// @Description  更新用户地址信息
// @Tags         地址模块
// @Accept       json
// @Produce      json
// @Param        user  body      request.UpdateAddress  true  "地址参数"
// @Success      200  {object}  response.Response
// @Failure      400   {object}  response.Response
// @Failure      500  {object}  response.Response
// @Router       /address/update [post]
func UpdateAddress(c *gin.Context) {
	var req request.UpdateAddress
	if err := c.ShouldBind(&req); err != nil {
		response.ParameterError(c, "参数错误", err.Error())
		return
	}
	res, err := config.UserClient.UpdateAddress(c, &__.UpdateAddressReq{
		Id:      req.Id,
		Address: req.Address,
	})
	if err != nil {
		response.SrvError(c, "添加地址失败", err.Error())
		return
	}
	response.Success(c, "更新地址成功", res)
}

// DeleteAddress
// @Summary      删除地址
// @Description  删除用户地址
// @Tags         地址模块
// @Accept       json
// @Produce      json
// @Param        user  body      request.GetId  true  "地址ID参数"
// @Success      200  {object}  response.Response
// @Failure      400   {object}  response.Response
// @Failure      500  {object}  response.Response
// @Router       /address/delete [post]
func DeleteAddress(c *gin.Context) {
	var req request.GetId
	if err := c.ShouldBind(&req); err != nil {
		response.ParameterError(c, "参数错误", err.Error())
		return
	}
	res, err := config.UserClient.DeleteAddress(c, &__.DeleteAddressReq{Id: req.Id})
	if err != nil {
		response.SrvError(c, "删除地址失败", err.Error())
		return
	}
	response.Success(c, "删除地址成功", res)
}
